function springBg() {
	$('#spring').backstretch([
		'static/images/seasons/backgroud/spring/1.jpg',
		'static/images/seasons/backgroud/spring/2.jpg',
		'static/images/seasons/backgroud/spring/3.jpg',
		'static/images/seasons/backgroud/spring/4.jpg',
		'static/images/seasons/backgroud/spring/5.jpg'
	], {
		fade: 1500, // 动画时长
		duration: 2500 // 切换延时
	});
	$('#spring').backstretch("pause");
}

function summerBg() {
	$('#summer').backstretch([
		'static/images/seasons/backgroud/summer/1.jpg',
		'static/images/seasons/backgroud/summer/2.jpg',
		'static/images/seasons/backgroud/summer/3.jpg',
		'static/images/seasons/backgroud/summer/4.jpg',
		'static/images/seasons/backgroud/summer/5.jpg'
	], {
		fade: 1500, // 动画时长
		duration: 2500 // 切换延时
	});
	$('#summer').backstretch("pause");
}

function autumnBg() {
	$('#autumn').backstretch([
		'static/images/seasons/backgroud/autumn/1.jpg',
		'static/images/seasons/backgroud/autumn/2.jpg',
		'static/images/seasons/backgroud/autumn/3.jpg',
		'static/images/seasons/backgroud/autumn/4.jpg',
		'static/images/seasons/backgroud/autumn/5.jpg'
	], {
		fade: 1500, // 动画时长
		duration: 2500 // 切换延时
	});
	$('#autumn').backstretch("pause");
}

function winterBg() {
	$('#winter').backstretch([
		'static/images/seasons/backgroud/winter/1.jpg',
		'static/images/seasons/backgroud/winter/2.jpg',
		'static/images/seasons/backgroud/winter/3.jpg',
		'static/images/seasons/backgroud/winter/4.jpg',
		'static/images/seasons/backgroud/winter/5.jpg'
	], {
		fade: 1500, // 动画时长
		duration: 2500 // 切换延时
	});
	$('#winter').backstretch("pause");
}

function changeSeason() {
	if ($("#spring").css('display') != 'none') {
		$("#spring").hide();
		$("#summer").show();
		$("#springMask").show();
		$('#spring').backstretch("pause");
		$('#summer').backstretch("show", 0);
		$('#summer').backstretch("resume");

	} else if ($("#summer").css('display') != 'none') {
		$("#summer").hide();
		$('#summer').backstretch("pause");
		$("#autumn").show();
		$("#summerMask").show();
		$('#autumn').backstretch("show", 0);
		$('#autumn').backstretch("resume");
	} else if ($("#autumn").css('display') != 'none') {
		$("#autumn").hide();
		$('#autumn').backstretch("pause");
		$("#winter").show();
		$("#autumnMask").show();
		$('#winter').backstretch("show", 0);
		$('#winter').backstretch("resume");
	} else if ($("#winter").css('display') != 'none') {
		$("#winter").hide();
		$('#winter').backstretch("pause");
		$("#spring").show();
		$("#winterMask").show();
		$('#spring').backstretch("show", 0);
		$('#spring').backstretch("resume");
	}
}

function clearSpring() {
	$("#springMask").fadeOut();
}

function clearSummer() {
	$("#summerMask").fadeOut();
}

function clearAutumn() {
	$("#autumnMask").fadeOut();
}

function clearWinter() {
	$("#winterMask").fadeOut();
}
$("#commentBlock").css("height",$(window).width()*2168/5000)

function confirmSeason() {
	springBg();
	summerBg();
	autumnBg();
	winterBg();
	var myDate = new Date();
	var month = myDate.getMonth();
	if (month >= 2 && month <= 4) {
		$("#spring").show();
		$('#spring').backstretch("show", 0);
		$('#spring').backstretch("resume");
		$('#commentBlock').css("background-image","url(./static/images/commentblockg.png)");
		$('#commentBlock').css("background-repeat","no-repeat");
		$('#commentBlock').css("background-size","100% auto");
		$('#commentBlock').css("-moz-background-size","100% auto");
		$('#page5color').css("background-color",'#F0EDF0');
		$('#leaf1').attr('src',"./static/images/leafg1.png");
		$('#leaf2').attr('src',"./static/images/leafg2.png");
		$('#leaf3').attr('src',"./static/images/leafg3.png");
		$('#leaf4').attr('src',"./static/images/leafg4.png");
		$('#leaf5').attr('src',"./static/images/leafg5.png");
	} else if (month >= 5 && month <= 7) {
		$("#summer").show();
		$('#summer').backstretch("show", 0);
		$('#summer').backstretch("resume");
		$('#commentBlock').css("background-image","url(./static/images/commentblockg.png)");
		$('#commentBlock').css("background-repeat","no-repeat");
		$('#commentBlock').css("background-size","100% auto");
		$('#commentBlock').css("-moz-background-size","100% auto");
		$('#page5color').css("background-color",'#F0EDF0');
		$('#leaf1').attr('src',"./static/images/leafg1.png");
		$('#leaf2').attr('src',"./static/images/leafg2.png");
		$('#leaf3').attr('src',"./static/images/leafg3.png");
		$('#leaf4').attr('src',"./static/images/leafg4.png");
		$('#leaf5').attr('src',"./static/images/leafg5.png");
	} else if (month >= 8 && month <= 10) {
		$("#autumn").show();
		$('#autumn').backstretch("show", 0);
		$('#autumn').backstretch("resume");
		$('#commentBlock').css("background-image","url(static/images/commentblock.png)");
		$('#commentBlock').css("background-repeat","no-repeat");
		$('#commentBlock').css("background-size","100% auto");
		$('#commentBlock').css("-moz-background-size","100% auto");
		$('#page5color').css("background-color",'#FDF5E8');
		$('#leaf1').attr('src',"./static/images/leaf1.png");
		$('#leaf2').attr('src',"./static/images/leaf2.png");
		$('#leaf3').attr('src',"./static/images/leaf3.png");
		$('#leaf4').attr('src',"./static/images/leaf4.png");
		$('#leaf5').attr('src',"./static/images/leaf5.png");
	} else {
		$("#winter").show();
		$('#winter').backstretch("show", 0);
		$('#winter').backstretch("resume");
		$('#commentBlock').css("background-image","url(static/images/commentblock.png)");
		$('#commentBlock').css("background-repeat","no-repeat");
		$('#commentBlock').css("background-size","100% auto");
		$('#commentBlock').css("-moz-background-size","100% auto");
		$('#page5color').css("background-color",'#FDF5E8');
		$('#leaf1').attr('src',"./static/images/leaf1.png");
		$('#leaf2').attr('src',"./static/images/leaf2.png");
		$('#leaf3').attr('src',"./static/images/leaf3.png");
		$('#leaf4').attr('src',"./static/images/leaf4.png");
		$('#leaf5').attr('src',"./static/images/leaf5.png");
	}
	$("#page2_main_pic1").show();
	$("#page2_sec_pic1").show();
}
confirmSeason();

function activeNav1() {
	$("#nav1").attr("class", "nav-item active");
	$("#nav2").attr("class", "nav-item")
	$("#nav3").attr("class", "nav-item")
	$("#nav4").attr("class", "nav-item")
	$("#nav5").attr("class", "nav-item")
	$("#nav6").attr("class", "nav-item")
}

function activeNav2() {
	$("#nav2").attr("class", "nav-item active");
	$("#nav1").attr("class", "nav-item")
	$("#nav3").attr("class", "nav-item")
	$("#nav4").attr("class", "nav-item")
	$("#nav5").attr("class", "nav-item")
	$("#nav6").attr("class", "nav-item")
}

function activeNav3() {
	$("#nav3").attr("class", "nav-item active");
	$("#nav2").attr("class", "nav-item")
	$("#nav1").attr("class", "nav-item")
	$("#nav4").attr("class", "nav-item")
	$("#nav5").attr("class", "nav-item")
	$("#nav6").attr("class", "nav-item")
}

function activeNav4() {
	$("#nav4").attr("class", "nav-item active");
	$("#nav2").attr("class", "nav-item")
	$("#nav3").attr("class", "nav-item")
	$("#nav1").attr("class", "nav-item")
	$("#nav5").attr("class", "nav-item")
	$("#nav6").attr("class", "nav-item")
}

function activeNav5() {
	$("#nav5").attr("class", "nav-item active");
	$("#nav4").attr("class", "nav-item")
	$("#nav2").attr("class", "nav-item")
	$("#nav3").attr("class", "nav-item")
	$("#nav1").attr("class", "nav-item")
	$("#nav6").attr("class", "nav-item")
}

function activeNav6() {
	$("#nav6").attr("class", "nav-item active");
	$("#nav4").attr("class", "nav-item")
	$("#nav2").attr("class", "nav-item")
	$("#nav3").attr("class", "nav-item")
	$("#nav1").attr("class", "nav-item")
	$("#nav5").attr("class", "nav-item")
}

function learnPage() {
	window.location = "pages/learningWorld.html";
}

function sportPage() {
	window.location = "pages/sport.html";
}

function happyPage() {
	window.location = "pages/entertainment.html";
}
function change_page2_pic_next() {
	// $("#page2_main_pic").stop(false, true);
	// $("#page2_main_pic").animate('{ right: -50}', 400);
	// $("#page2_main_pic").fadeOut("slow");
	// $("#page2_sec_pic").stop(false, true);
	// $("#page2_sec_pic").animate('{ right: 30!important, top:200}', 1000);
	if ($("#page2_main_pic1").css('display') != 'none') {
		$("#page2_main_pic1").fadeOut("slow");
		$("#page2_main_pic2").fadeIn("slow");
		$("#page2_sec_pic1").fadeOut("slow");
		$("#page2_sec_pic2").fadeIn("slow");
	} else if ($("#page2_main_pic2").css('display') != 'none') {
		$("#page2_main_pic2").fadeOut("slow");
		$("#page2_main_pic3").fadeIn("slow");
		$("#page2_sec_pic2").fadeOut("slow");
		$("#page2_sec_pic3").fadeIn("slow");
	} else if ($("#page2_main_pic3").css('display') != 'none') {
		$("#page2_main_pic3").fadeOut("slow");
		$("#page2_main_pic4").fadeIn("slow");
		$("#page2_sec_pic3").fadeOut("slow");
		$("#page2_sec_pic4").fadeIn("slow");
	} else if ($("#page2_main_pic4").css('display') != 'none') {
		$("#page2_main_pic4").fadeOut("slow");
		$("#page2_main_pic1").fadeIn("slow");
		$("#page2_sec_pic4").fadeOut("slow");
		$("#page2_sec_pic1").fadeIn("slow");
	}
}
function change_page2_pic_front() {
	// $("#page2_main_pic").stop(false, true);
	// $("#page2_main_pic").animate('{ right: -50}', 400);
	// $("#page2_main_pic").fadeOut("slow");
	// $("#page2_sec_pic").stop(false, true);
	// $("#page2_sec_pic").animate('{ right: 30!important, top:200}', 1000);
	if ($("#page2_main_pic1").css('display') != 'none') {
		$("#page2_main_pic1").fadeOut("slow");
		$("#page2_main_pic4").fadeIn("slow");
		$("#page2_sec_pic1").fadeOut("slow");
		$("#page2_sec_pic4").fadeIn("slow");
	} else if ($("#page2_main_pic2").css('display') != 'none') {
		$("#page2_main_pic2").fadeOut("slow");
		$("#page2_main_pic1").fadeIn("slow");
		$("#page2_sec_pic2").fadeOut("slow");
		$("#page2_sec_pic1").fadeIn("slow");
	} else if ($("#page2_main_pic3").css('display') != 'none') {
		$("#page2_main_pic3").fadeOut("slow");
		$("#page2_main_pic2").fadeIn("slow");
		$("#page2_sec_pic3").fadeOut("slow");
		$("#page2_sec_pic2").fadeIn("slow");
	} else if ($("#page2_main_pic4").css('display') != 'none') {
		$("#page2_main_pic4").fadeOut("slow");
		$("#page2_main_pic3").fadeIn("slow");
		$("#page2_sec_pic4").fadeOut("slow");
		$("#page2_sec_pic3").fadeIn("slow");
	}
}

$("#comment").hide();
$("#put_away_comment").hide();

$("#get_comment").click(function () {
	$("#comment").fadeIn(300);
	$("#get_comment").hide();
	$("#put_away_comment").show();
});
$("#put_away_comment").click(function () {
	$("#comment").fadeOut(300);
	$("#put_away_comment").hide();
	$("#get_comment").show();
});
$('li').click(function () {
	$(this).addClass('active').siblings().removeClass('active');
});

$(document).ready(function() {
  
	//Initiliaze
	var itemList, item, className, thisItem, newOrder, itemDesc, desc;
	
	itemList  = $('#itemlist');
	item      = itemList.children('img');
	
	itemDesc  = $('#itemdescription');
	desc      = itemDesc.children('span');
	
	//Add class name for each item
	item.each(function(index) {
	  
	  className  = 'item-' + index;
	  
	  $(this).addClass(className).attr('data-order', index);
	  
	});
	
	//Show first item description
	desc.filter(':first-child').fadeIn();
	
	//On clicked fire animation
	item.on('click', function() {
	  
	  thisItem  = $(this);
	  thisOrder = parseInt(thisItem.attr('data-order')) - 1;
  
	  thisItem.addClass('show');
	  
	  //Reorder item position
	  item.on('animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd', function() { 
	  
		thisItem.removeClass().addClass('item-0').attr('data-order', '0');
	
		//Show selected item description
		desc.hide();
		desc.filter('[data-for=' + thisItem.attr('id') + ']' ).fadeIn('fast');
	  });
  
	  //Move siblings items backward
	  window.setTimeout(function () {    
		
		for(var i = thisOrder; i >= 0; i--) {
		
		  //Reorder item position
		  movedItem = item.filter('[data-order=' + i + ']');
		  newOrder  = parseInt(movedItem.attr('data-order')) + 1;
		  className = 'item-' + newOrder;
		  
		  //Move them with transition
		  movedItem.removeClass().addClass('transition ' + className).attr('data-order', newOrder);
		  
		  //Remove their transition
		  item.on('transitionend webkitTransitionEnd MSTransitionEnd oTransitionEnd', function() { 
			item.removeClass('transition');
		  });
		}  
	  }, 500);
	});
});
$(function () {
	new Swiper(".swiper-container", {

		//默认功能属性
		speed: 250,
		slidesPerView: 3,
		spaceBetween: 0,
		slidesPerGroup: 3,
		loop: true,
		autoplay: true,

		//分页索引
		pagination: {
			el: ".swiper-pagination",
			clickable: true
		},

		//分页按钮
		navigation: {
			nextEl: ".swiper-button-next",
			prevEl: ".swiper-button-prev"
		}

	});
})
function submitForm() {
	$("#commentSub").ajaxSubmit(function (result) {
		if (result.status == true) {
			alert("评论成功");

		} else {
			alert("评论成功");
		}
	});
}
layui.use('laypage', function () {
	var laypage = layui.laypage;
	$.ajax({
		type: "GET",
		async: false,
		url: "comments/queryComments.php?page=page1",
		dataType: "json",
		success: function (data) {
			laypage.render({
				elem: 'layerpage',
				count: data.total,
				limit: 5,
				jump: function (obj, first) {
					$.ajax({
						type: "GET",
						async: false,
						url: "comments/queryComments.php?page=page1&cur=" + obj.curr,
						dataType: "json",
						success: function (data) {
							if (first) {
								var i;
								for (i = 0; i < data.total; i++) {
									$("#userComment" + (i + 1)).append(data[0][i].content);
								}
							} else {
								var i;
								for (i = 0; i < data.total; i++) {
									$("#userComment" + (i + 1)).empty();
									$("#userComment" + (i + 1)).append(data[0][i].content);
								}
							}
						},
						error: function () {
							alert('fail');
						}
					});
				},
				theme: "#ba2a17"
			});
		},
		error: function () {
			$("#userComment1").append("秋日的江安简直不要太美，特别是黄昏时节，落霞使人沉醉在这无限光阴之中，别有一番风味");
			$("#userComment2").append("江安河畔，竹外桃花三两枝，春江水暖鸭先知，好好珍惜能在川大江安河畔的时光吧");
			$("#userComment3").append("一眼就看到了右下角的猫猫，我川的猫猫可真是会撒娇呢");
			$("#userComment4").append("一眼就看到了右下角的猫猫，我川的猫猫可真是会撒娇呢");
			$("#userComment5").append("一眼就看到了右下角的猫猫，我川的猫猫可真是会撒娇呢");
		}
	});
});
